<?php

use think\migration\Migrator;
use think\migration\db\Column;

class CreateContentTbl extends Migrator
{
    const TBL_NAME = 'content';
    const RELATED_ARTICLE_NAME = 'article';

    public function change()
    {
        // create the table
        $table  =  $this->table(addTablePrefix(self::TBL_NAME),[
            'engine'=>'InnoDB',
            'comment' => '文章内容表',
            'signed' => false
        ]);
        $table
            ->addColumn('article_id', 'integer',array('signed' => false,'comment'=>'所属文章'))
            ->addColumn('content', 'text',array('comment'=>'文章内容'))
            ->addForeignKey('article_id', addTablePrefix(self::RELATED_ARTICLE_NAME), 'id', ['delete'=> 'CASCADE', 'update'=> 'NO_ACTION'])
            ->create();
    }
}
